import _ from 'lodash';
import { ElNotification } from 'element-plus';
import { SortOrderMap } from 'src/common/const';
const utils: Utils = {
    cloneDeep: (value: any) => _.cloneDeep(value),
    commonNotification: (conditionData) => {
        if (conditionData.condition) {
            ElNotification({
                message: conditionData.msg_success || '操作成功',
                type: 'success'
            })
            conditionData.callback_success && conditionData.callback_success()
        } else {
            ElNotification({
                message: conditionData.msg_failed || '操作失败',
                type: conditionData.type_failed || 'error'
            })
            conditionData.callback_failed && conditionData.callback_failed()
        }
    },
    getTodayDate: () => {
        const currentDate = new Date();
        const year = currentDate.getFullYear(); // 获取当前年份
        const month = currentDate.getMonth() + 1; // 获取当前月份，注意月份从0开始计数，需要加1
        const day = currentDate.getDate(); // 获取当前日期
        const target = `${year}-${(month < 10 ? '0' : '') + month}-${(day < 10 ? '0' : '') + day}`;
        return target;
    },
    uniqueObjArray: (items, filterKey) => {
        if (!items || !items.length) return []
        return items.filter((item, index, self) =>
            self.findIndex(i => i[filterKey] === item[filterKey]) === index
        )
    },
    commonSortChage: (searchForm: any, callback: Function) => {
        return ({ prop, order }: any) => {
            if (order) {
                searchForm.value.order = SortOrderMap[order as keyof typeof SortOrderMap]
                searchForm.value.columnName = prop === 'clueNum' ? 'num' : prop
            } else {
                searchForm.value.order = SortOrderMap.descending
                searchForm.value.columnName = 'addtime'
            }
            callback && callback()
        }
    }
}
export default utils